import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as AllStore from './stores'
import * as serviceWorker from './serviceWorker';
import {loginStore} from './login/store'
import {Provider} from 'mobx-react';
import {autorun} from 'mobx'

const newError = (_date) => {
    let date = _date
    return (newDate) => {
        if(newDate !== date) {
            date = newDate;
            return true
        } else {
            return false
        }
    }
}
const isNewError = newError(AllStore.error.state.date)
autorun(() => {
    if(isNewError(AllStore.error.state.date)) {
        return AllStore.error.errorInfo()
    }
})


class Timer extends React.Component {

    render() {
        return (
            // 可以增加任意多个store，子组件通过@inject("store")
            <div>
                <Provider {...AllStore} loginStore={loginStore}>
                    <App />
                </Provider>
            </div>

        )
    }
};


ReactDOM.render(<Timer />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
